package com.ruoyi.decision.service.impl;

import com.ruoyi.common.core.domain.entity.SysDictData;
import com.ruoyi.decision.domain.Scene;
import com.ruoyi.decision.domain.Menu;
import com.ruoyi.decision.mapper.SceneMapper;
import com.ruoyi.decision.service.ISceneService;
import com.ruoyi.system.service.ISysDictDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * 决策场景Service业务层处理
 * 
 * @author zbw
 * @date 2022-07-19
 */
@Service
public class SceneServiceImpl implements ISceneService 
{
    @Autowired
    private SceneMapper sceneMapper;

    @Autowired
    private ISysDictDataService iSysDictDataService;

    /**
     * 查询决策场景
     * 
     * @param sceneId 决策场景主键
     * @return 决策场景
     */
    @Override
    public Scene selectSceneBySceneId(String sceneId)
    {
        return sceneMapper.selectSceneBySceneId(sceneId);
    }

    /**
     * 查询决策场景列表
     * 
     * @param scene 决策场景
     * @return 决策场景
     */
    @Override
    public List<Scene> selectSceneList(Scene scene)
    {
        return sceneMapper.selectSceneList(scene);
    }

    /**
     * 新增决策场景
     * 
     * @param scene 决策场景
     * @return 结果
     */
    @Override
    public int insertScene(Scene scene)
    {
        String sceneId = UUID.randomUUID().toString().toLowerCase(Locale.ROOT).replace("-","");
        scene.setSceneId(sceneId);
        return sceneMapper.insertScene(scene);
    }

    /**
     * 修改决策场景
     * 
     * @param scene 决策场景
     * @return 结果
     */
    @Override
    public int updateScene(Scene scene)
    {
        return sceneMapper.updateScene(scene);
    }

    /**
     * 批量删除决策场景
     * 
     * @param sceneIds 需要删除的决策场景主键
     * @return 结果
     */
    @Override
    public int deleteSceneBySceneIds(String[] sceneIds)
    {
        return sceneMapper.deleteSceneBySceneIds(sceneIds);
    }

    /**
     * 删除决策场景信息
     * 
     * @param sceneId 决策场景主键
     * @return 结果
     */
    @Override
    public int deleteSceneBySceneId(String sceneId)
    {
        return sceneMapper.deleteSceneBySceneId(sceneId);
    }

    @Override
    public List<Menu> treemenu(Scene scene) {
        String a="rts_scene_type";
        SysDictData sysDictData1 = new SysDictData();
        sysDictData1.setDictType(a);
        List<SysDictData> sysDictData = iSysDictDataService.selectDictDataList(sysDictData1);
        List<Menu> data = new ArrayList<>();
        List<Scene> scenes = sceneMapper.selectSceneList(null);
        for (SysDictData b : sysDictData) {
            Menu vo = new Menu();
            vo.setId(b.getDictCode().toString());
            vo.setName(b.getDictLabel());
            vo.setpId(b.getDictValue());
            Menu menu = new Menu();
            for (Scene scene1 : scenes) {
                if (vo.getpId().equals(scene1.getSceneType())){
                    List<Menu> s = new ArrayList<>();
                    menu.setName(scene1.getSceneName());
                    menu.setId(scene1.getSceneId());
                    menu.setpId(scene1.getSceneType());
                    s.add(menu);
                    vo.setChildren(s);
                }
            }

            data.add(vo);
        }

        return data;
    }
}
